package com.lagou.rpc.consumer.controller;

import com.lagou.rpc.api.IUserService;
import com.lagou.rpc.consumer.proxy.RpcClientProxy;
import com.lagou.rpc.pojo.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    private boolean flag = false;
    IUserService userService = (IUserService) RpcClientProxy.createProxy(IUserService.class, 0);
    IUserService userService2 = (IUserService) RpcClientProxy.createProxy(IUserService.class, 1);

    @GetMapping("/test")
    public User getUserById(Integer id) {
        User user = null;
        if(!flag) {
            user = userService.getById(id);
            flag = true;
        } else {
            user = userService2.getById(id);
            flag = false;
        }
        return user;
    }
}
